﻿using BCCommon.Enums;
using BCData.WeChatComponent.WeChatMessageRecord;
using BCEntity.WeChatComponent.WeChatMessageRecord;
using System;
using System.Collections.Generic;
using System.Text;
using WeChatSDK.WeChatDto.Conversation.ReceivingMessage;

namespace BCService.WeChatComponent.WeChatHandleService.LocationMessageService
{
    /// <summary>
    /// 微信位置消息处理
    /// </summary>
    public class LocationMessageService : IWeChatMessageHandle
    {
        private readonly IWeChatMessageRecordData weChatMessageRecordData;

        public LocationMessageService(IWeChatMessageRecordData weChatMessageRecordData)
        {
            this.weChatMessageRecordData = weChatMessageRecordData;
        }

        public string HandleMessage(ReceivingMessageDto message)
        {
            LocationMessageDto locationMessageDto = (LocationMessageDto)message;
            WeChatMessageRecordEntity weChatMessageRecordEntity = this.RecordReceivingMessage(locationMessageDto);
            string response = "success";
            return response;
        }

        private WeChatMessageRecordEntity RecordReceivingMessage(LocationMessageDto locationMessageDto)
        {
            WeChatMessageRecordEntity entity = new WeChatMessageRecordEntity()
            {
                ToUserName = locationMessageDto.ToUserName,
                FromUserName = locationMessageDto.FromUserName,
                MessageType = WeChatMessageType.Location,
                MessageId = locationMessageDto.MsgId,
                LocationX = locationMessageDto.Location_X,
                LocationY = locationMessageDto.Location_Y,
                Scale = locationMessageDto.Scale,
                LocationLabel = locationMessageDto.Label,
                IsReply = false
            };
            return this.weChatMessageRecordData.Add(entity);
        }
    }
}
